import {Component, OnInit, ViewChild} from "@angular/core";
import {USER} from "../../service/user.service";
import {ROUTE} from "../../service/route.service";
import {PaymentViewComponent} from "../payment-view/payment-view.component";
import {OnekeyRepairViewComponent} from "../onekey-repair-view/onekey-repair-view.component";
import {LoginModalViewComponent} from "../login-modal-view/login-modal-view.component";
import {UserModel} from "../../model/user.model";

@Component({
  selector: 'app-life-service-view',
  templateUrl: 'life-service-view.component.html',
  styleUrls: ['life-service-view.component.scss']
})
export class LifeServiceViewComponent implements OnInit {
  @ViewChild(LoginModalViewComponent) public loginModal:any;
  @ViewChild(PaymentViewComponent)public paymentModal:any;
  @ViewChild(OnekeyRepairViewComponent)public repairModal:any;

  constructor(private route:ROUTE,private USER:USER) { }
  ngOnInit() {
    this.user = this.USER.get() as UserModel;
  }
  user:UserModel;
  showLoginModal:boolean=false;

  static defaultItems:any = [
    {name: '生活缴费', icon: 'wficon-living-payment'},
    {name: '品质保洁', icon: 'wficon-clean-keeping'},
    {name: '家居租赁', icon: 'wficon-furniture'},
    {name: '闪电维修', icon: 'wficon-maintain'},
    {name: '快递服务', icon: 'wficon-courier-service'}
  ];
  items:any = LifeServiceViewComponent.defaultItems;

  serviceItems:any=[
    {content: '生活缴费文案',btn: '我要缴费',onClick: this.showPaymentModal.bind(this)},
    {content: '品质保洁文案',btn: '保洁商城',onClick: this.goToCleaningMallView.bind(this)},
    {content: '家居租赁文案',btn: '我要租赁',onClick: this.goToRentingMallView.bind(this)},
    {content: '闪电维修文案',btn: '申请维修',onClick: this.showRepairModal.bind(this)},
    {content: '快递服务文案'}
  ];

  closeLogin(result:Object){
    if(result instanceof UserModel){
      this.user=result;
      this.USER.update(result);
    }
    this.showLoginModal=false;
  }

  showPaymentModal(){
    if(this.user==null){
      this.showLoginModal = true;
    }else{
      this.paymentModal.showModal();
    }
  };

  goToCleaningMallView(){
    this.route.goCleaningMallView();
  }

  goToRentingMallView(){
    this.route.goRentingMallView();
  };

  showRepairModal(){
    if(this.user==null){
      this.showLoginModal = true;
    }else{
      this.repairModal.showModal();
    }
  }
}
